/***************************************************************************
 * File name: EPubUtil.h
 * Original author: caizhifei2003@163.com
 * Date: 2013.02.20
 ***************************************************************************/
#ifndef _EPUB_UTIL_H_
#define _EPUB_UTIL_H_

// Delete allocated memory safely.
#ifndef SAFE_DELETE
#define SAFE_DELETE(ptr) {if((ptr) != NULL) { delete (ptr); (ptr) = NULL; }}
#endif


// Delete allocated memory array safely.
#ifndef SAFE_DELETE_ARRAY
#define SAFE_DELETE_ARRAY(ptr) {if((ptr) != NULL) { delete[] (ptr); (ptr) = NULL; }}
#endif



#include "EPubTypes.h"
#include <TinyXml\tinyxml.h>
#include <string>
#include <map>
#include <vector>

EPUB_Size EPub_String_Split(const std::string &content, const std::string &delimiters, std::vector<std::string> &output);

EPUB_Size EPub_Xml_ParseAttribute(const std::string &pattern, std::map<std::string, std::string> &attrs);
EPUB_Size EPub_Xml_ParseElement(const std::string &pattern, std::vector<std::string> &elems);

bool EPub_Xml_Match_Attribute(const TiXmlElement *elem, const std::string &pattern);
EPUB_Result EPub_Xml_Attribute(const TiXmlElement *elem, const std::string &name, std::string &value);
EPUB_Result EPub_Xml_Attribute(const TiXmlElement *elem, const std::string &pattern, const std::string &name, std::string &value);

EPUB_Result EPub_Xml_Element(const TiXmlDocument *doc, const std::string &pattern_elem, const TiXmlElement **out);
EPUB_Result EPub_Xml_Element(const TiXmlElement *parent, const std::string &pattern_elem, const TiXmlElement **out);
EPUB_Result EPub_Xml_Element(const TiXmlElement *parent, const std::string &pattern_elem, const std::string &pattern_attr, const TiXmlElement **out);

EPUB_Result EPub_Xml_Text(const TiXmlElement *elem, std::string &out);
EPUB_Result EPub_Xml_Text(const TiXmlElement *elem, const std::string &pattern_elem, std::string &out);

#endif // _EPUB_UTIL_H_